home *** CD-ROM | disk | FTP | other *** search
/ Gamecube Preview CD ROM / 04 - Gamecube Preview CD-ROM.iso / pc / site / js / window.js < prev   
Encoding:
JavaScript  |  2001-09-06  |  5.2 KB  |  138 lines

  1. // Window functions  v1.01
  2. // http://www.dithered.com/javascript/window/index.html
  3. // code by Chris Nott (chris@dithered.com)
  4.  
  5. /*******************************************************************************
  6.     Popup Window openers
  7. *******************************************************************************/
  8.  
  9. var winReference = null;
  10.  
  11.  
  12. // Open a window at a given position on the screen
  13. function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
  14.     
  15.     // ie4.5 mac - windows are 2 pixels too short; if a statusbar is used, the window will be an additional 15 pixels short
  16.     var agent = navigator.userAgent.toLowerCase();
  17.     if (agent.indexOf("mac")!=-1 && agent.indexOf("msie") != -1 && agent.indexOf("msie 5.0")==-1) {
  18.         height += 2;
  19.         if (status) height += 15;
  20.     }
  21.  
  22.     // Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
  23.     width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
  24.  
  25.     var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
  26.     var reference = openWindow(url, name, properties, openerName);
  27.     
  28.     // resize window in ie if we can resize in ns; very messy
  29.     // commented out because openPositionedWindow() doesn't set the resizable attribute
  30.     // left in for reference
  31.     /*if (resizable && agent.indexOf("msie") != -1) {
  32.         if (agent.indexOf("mac") != -1) {
  33.             height += (status) ? 15 : 2;
  34.             if (parseFloat(navigator.appVersion) > 5) width -= 11;
  35.         }
  36.         else {
  37.             height += (status) ? 49 : 31;
  38.             width += 13;
  39.         }
  40.         setTimeout('if (reference != null && !reference.closed) reference.resizeTo(' + width + ',' + height + ');', 150);
  41.     }*/
  42.  
  43.     return reference;
  44. }
  45.  
  46.  
  47. // Open a window at the center of the screen
  48. function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
  49.     var x = 0;
  50.     var y = 0;
  51.     if (screen) x = (screen.availWidth - width) / 2;
  52.     if (screen) y = (screen.availHeight - height) / 2;
  53.     if (!status) status == '';
  54.     if (!openerName) openerName == '';
  55.     var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
  56.     return reference;
  57. }    
  58.  
  59.  
  60. // Open a full-screen window (different from IE's fullscreen option)
  61. function openMaxedWindow(url, name, scrollbars, openerName) {
  62.     var width  = 600;
  63.     var height = 800;
  64.     if (screen) width  = screen.width - 10;
  65.     if (screen) height = screen.height - 30;
  66.     var reference = openPositionedWindow(url, name, width, height, 0, 0, false, scrollbars, openerName, moreProperties);
  67.     return reference;
  68. }
  69.  
  70.  
  71. // Open a full-chrome (all GUI elements) window
  72. // This is like using a target="_blank" in a normal link but allows focussing the window
  73. function openFullChromeWindow(url, name, openerName) {
  74.     return openWindow(url, name, 'directories,location,menubar,resizable,scrollbars,status,toolbar');
  75. }
  76.  
  77.  
  78. // Core utility function that actually creates the window and gives focus to it
  79. function openWindow(url, name, properties, openerName) {
  80.  
  81.     // ie4.x pc can't give focus to windows containing documents from a different domain
  82.     // in this case, initially load a local interstisial page to allow focussing before loading final url
  83.     var agent = navigator.userAgent.toLowerCase();
  84.     if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
  85.         winReference = window.open('about:blank', name, properties);
  86.         
  87.         setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
  88.     }
  89.     else {
  90.         winReference = window.open(url, name, properties);
  91.     }
  92.  
  93.     // ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
  94.     setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
  95.     
  96.     if (openerName) self.name = openerName;
  97.     return winReference;
  98. }
  99.  
  100.  
  101. /*******************************************************************************
  102.     Modal Dialog controls
  103. *******************************************************************************/
  104.  
  105. // Close a dialog
  106. // Call from onunload event handler of any page that can create a dialog
  107. function closeDialog(dialog) {
  108.     if (dialog && dialog.closed != true) dialog.close();
  109. }
  110.  
  111.  
  112. // Close parent popup
  113. // Call from onload event handler of any page that could be created from a dialog
  114. function closeParentDialog() {
  115.     if (top.opener && isWindowPopup(top.opener)) {
  116.         root = top.opener.top.opener;
  117.         top.opener.close();
  118.         top.opener = root;
  119.     }
  120. }
  121.  
  122.  
  123. // Check if a window is a popup
  124. function isWindowPopup(win) {
  125.     return ((win.opener) ? true : false);
  126. }
  127.  
  128. function openVideoWindow(url) {
  129. return openCenteredWindow(url, 'video', 500, 391, '', '', '' ) 
  130. }
  131.  
  132. function openScreenWindow(url) {
  133. return openCenteredWindow(url, 'screens', 540, 420, '', '', '' ) 
  134. }
  135.  
  136. function openCopyWindow(url) {
  137. return openCenteredWindow(url, 'copy', 540, 540, 'status', 'scrollbars', '' ) 
  138. }